feat: expose full CLI metadata in SDK types and responses #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR exposes the complete Claude CLI metadata that was previously being filtered out by the SDK's
parseMessage()method.After analyzing the actual CLI output (
claude --verbose --output-format stream-json), we discovered 35 missing features across three categories:What's Included
Extended Type Definitions
ResultMessage & CLIResultOutput:
ModelUsageInfointerface for per-model breakdownduration_ms,duration_api_ms,num_turnsis_error(boolean),result(simplified string access)service_tier,server_tool_use.web_search_requestsephemeral_5m_input_tokens,ephemeral_1h_input_tokensmodelUsage(per-model token counts, costs, web searches, context window)permission_denialsarrayuuidfieldSystemMessage:
Field Additions (32+ total)
Performance Metrics (3):
duration_ms- Total query durationduration_api_ms- API response timenum_turns- Number of conversation turnsError & Result (2):
is_error- Boolean error statusresult- Simplified result stringToken Usage (8):
input_tokens,output_tokens(existing)cache_creation_input_tokens,cache_read_input_tokens(existing)service_tier- Service tier informationserver_tool_use.web_search_requests- Web search countcache_creation.ephemeral_5m_input_tokens- 5-minute cache tiercache_creation.ephemeral_1h_input_tokens- 1-hour cache tierCost Breakdown (5):
input_cost,output_costcache_creation_cost,cache_read_costtotal_costModel Usage (per model, 6 fields):
inputTokens,outputTokenscacheReadInputTokens,cacheCreationInputTokenswebSearchRequests- Web searches per modelcontextWindow- Model's context window sizecostUSD- Cost per modelTracking (2):
permission_denials- Array of denied permissionsuuid- Request UUID for correlationSystem Capabilities (12):
cwd,model,claude_code_versionpermissionMode,apiKeySource,output_styletools(19 available),mcp_servers(with connection status)slash_commands(23 available),agents(19 available)skills,uuidNew ResponseParser Methods (7 total)
Performance & Tracking:
getPerformanceMetrics()- Access timing and turn informationgetRequestUUID()- Get request UUID for correlationPermissions & Audit:
getPermissionDenials()- Check which permissions were deniedCapabilities Discovery:
getSystemCapabilities()- Get available tools, agents, MCP servers, etc.Cost & Usage Analytics:
getModelUsageBreakdown()- Access per-model usage statisticsgetWebSearchUsage()- Track web searches (total + per-model breakdown)getCacheBreakdown()- Analyze cache tier usage (5m vs 1h)Type Exports
All new types properly exported from
src/index.ts:ModelUsageInfoPerformanceMetricsSystemCapabilitiesWebSearchUsageCacheBreakdownToolExecutionUsageStatsBackwards Compatibility
✅ Fully backwards compatible - All new fields are optional
✅ All existing methods continue to work unchanged
✅ New methods are purely additive
✅ No breaking changes to any interfaces
Implementation Details
parseMessage() Changes (src/_internal/client.ts)
null)is_error,result, enhancedusage, fullcost,modelUsageType Safety Fixes
is_error,result, web search tracking, cache tiersModelUsageInfowithwebSearchRequestsandcontextWindowtotal_cost_usd)Use Cases
Testing
✅ Code compiles without TypeScript errors
✅ All new types properly defined and exported
✅ ResponseParser methods properly implemented
✅ No linter errors
✅ Backwards compatible with existing code
✅ All fields extracted from CLI output
Commits
7c0f759: Initial implementation (26 fields + 5 methods)
b040584: Gap filling (6 additional fields + 2 methods + 4 exports)
Resolves
Closes #12
Summary Table
Total: 32+ fields added, 7 convenience methods, complete type safety